#!/bin/sh

CUR_PATH=$(cd "$(dirname "$0")"; pwd)
source ${CUR_PATH}/../mysql8_server.conf
curr_date=$1
suffix=`date -d "${curr_date}" +%y`
#echo $curr_date
#echo $curr_year
#echo $next_year
#echo $suffix

month_array=('01' '02' '03' '04' '05' '06' '07' '08' '09' '10' '11' '12')
for month in ${month_array[@]}
    do
        datename=${suffix}${month}
        create_table_sql=$(cat <<EOF

        DROP TABLE IF EXISTS vehicle_drivingnumberinarea_${datename};
        CREATE TABLE vehicle_drivingnumberinarea_${datename} (
          id int NOT NULL AUTO_INCREMENT,
          district bigint DEFAULT NULL COMMENT '经纬度对应地区编码',
          name varchar(32) DEFAULT NULL COMMENT '经纬度对应地区名称',
          type int DEFAULT NULL COMMENT '地区类型：省:2市:1服务站:5',
          times int DEFAULT NULL COMMENT '经过地区车次',
          detail json DEFAULT NULL COMMENT '位置点明细',
          day int DEFAULT NULL COMMENT '数据日期',
          created_time datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建日期',
          update_time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
          PRIMARY KEY (id),
          KEY index_bt_district_type_day (district,type,day)
        ) ENGINE=InnoDB AUTO_INCREMENT=665 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci ROW_FORMAT=COMPACT COMMENT='区域车次统计表'


EOF
)
#echo ${create_table_sql}
mysql -h${HOSTNAME}  -P${PORT}  -u${USERNAME} -p${PASSWORD} ${DBNAME} -e "${create_table_sql}"
if [ $? -ne 0 ] ; then
  echo "表创建失败"
else
  echo "表创建成功"
fi
    done

